﻿define(["jQuery", "kendo", "config", "utils", "localdata"],
        function ($, kendo, config, utils, localdata) {


            /*RETURN*/
            /*This class contains all datasources that are driver related*/
            return {

              
                //driverDataSource
                driverDataSource :  new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: config.driverURL,
                            dataType: "jsonp"
                        },  //end read
                        update: {
                            url: config.driverURL + "/Update",
                            dataType: "jsonp",
                            type: "POST"
                        },   //end update
                        destroy: {
                            url: config.driverURL + "/Destroy",
                            dataType: "jsonp"
                        },   //end destroy
                        create: {
                            url: config.driverURL + "/Create",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json",
                            complete: function (jqXHR, textStatus) {
                                console.log(jqXHR);
                                console.log(textStatus, "update")
                            },
                            jsonp: false,
                            jsonpCallback: function (data) {
                                alert(data);
                            },
                            success: function (data) {
                                console.log(data);
                                console.log('after data success');
                            }//"UserCallback" //required by jQuery
                        },   //end create
                        parameterMap: function (options, operation) {
                            if (operation !== "read" && options.models) {
                                console.log(kendo.stringify(options.models));
                                //return {options.models};
                                //return { sucks: kendo.stringify(options.models) };
                               return utils.formatToWebAPiJSon(options.models);
                            }
                        }   //end parameter map
                    },  //end transport
                    change: function (data) {
                        //OWL.readyForCheckout = dsReviewList._data.length;
                        console.log(data);
                    },
                    error: function (xhr, error) {
                        console.log(xhr);
                        console.log(error);
                    },
                    UserCallback: function (data) {
                        console.log('is that true');
                    },
                    batch: true,
                    pageSize: 20,
                    schema: {
                        model: {
                            id: "IDDriver",
                            fields: {
                                IDDriver: { editable: false, nullable: true },
                                Name: { type: "string" },
                                Email: { type: "string" },
                                Telephone: { type: "string" },
                                IDUser: { type: "number" },
                                QRCodeImage: { type: "string" },
                                ImageURL: { type: "string" },
                                DriverImage: { type: "string" },
                                DriverImageDateTaken: { type: "date" },
                                DateCreated: { type: "date" },
                                DateUpdated: { type: "date" },
                                DateInactive: { type: "date" },
                                User_DateCreated: { type: "date" },
                                User_DateInactive: { type: "date" },
                                User_DateUpdated: { type: "date" },

                            }   //end fields
                        }   //end model
                    }   //end schema
                }) //end datasource
            }   //end return
        }); /* End define */